package com.shujia.common_util.three;

import com.shujia.common_util.one.Helloworld;
import org.junit.Test;

public class EqualsDemo {


    @Test
    public void test1() {
        String s1 = new String("abcd");
        String s2 = new String("abcd");
        System.out.println(System.identityHashCode(s1));
        System.out.println(System.identityHashCode(s2));

        System.out.println(s1 == s2);// false

        // String 重写了equals方法, 重写的逻辑是比较字符串的内容
        System.out.println(s1.equals(s2));// true


    }


    /*
    public boolean equals(Object obj) {
        return (this == obj);
    }
    == 就是比较内存地址值
     */
    public static void main(String[] args) {
        EqualsDemo demo = new EqualsDemo();
        // 地址值的赋值
        EqualsDemo demo1 = demo;
        Integer i = 10;
        String str = "abc";
        Helloworld helloworld = new Helloworld();
        System.out.println(demo.equals(i));// demo == i
        System.out.println(demo.equals(str));// demo == str
        System.out.println(demo.equals(helloworld));// demo == helloword

        System.out.println(demo == demo1);
        System.out.println(demo.equals(demo1));

        int x = 10;
        System.out.println(i == x);

        // 如果比较引用数据类型, 没有继承关系会编译报错
        // boolean flag = demo == str;
    }
}
